﻿using UnityEngine;
using System.Collections;
using Network;
using Network.Messages;
using System;
using System.Collections.Generic;
//using GwScene;
//using UniScene;

public class NetSender : Singleton<NetSender>
{
    public void SendRequestMachineTrap(UInt64 id,int type)
    {
        var msg = new U2GS_RequestMachineTrap();
        msg.m_id = id;
        msg.m_op = (SByte)type;
        Networker.Instance.SendMessage(msg);
    }

   /* public void SendRequestStopMove(Entity host)
    {
        var msg = new U2GS_StopMove();
        msg.m_id = host.code;
        msg.m_posX = host.position2d.x;
        msg.m_posY = host.position2d.y;
        Networker.Instance.SendMessage(msg);
#if _DEBUG
        SinglePanelManger.Instance.debugsPanel.GetSendMsgInfo((Character)host, msg);
#endif
    }*/

    /*public void SendRequestUseSkill(Skill skill)
    {
        var msg = new C2S_PlayerUseSkill();
        msg.m_code = skill.owner.code;
        msg.m_skillId = skill.skillId;
        msg.m_serial = skill.instId;
        msg.m_targetCodeList = skill.targetResult.targetCodeList;
        Networker.Instance.SendMessage(msg);
#if _DEBUG
        SinglePanelManger.Instance.debugsPanel.GetSendMsgInfo(skill.owner, msg);
#endif
    }*/

    public void SendRequestKeepAlive()
    {
        var msg = new U2GS_KeepAlive();
        Networker.Instance.SendMessage(msg);
    }

    public void SendRequestEnterMap()
    {
        var msg = new U2GS_EnterMap();
        msg.m_id = GameSceneManager.Instance.localPlayer.code;
        Networker.Instance.SendMessage(msg);
    }

    /*public void SendRequestChangeSkill(SkillDrag dragObj,SkillDrop drapObj)
    {
        var msg = new U2GS_BindPlayerSkill();
        msg.m_skillID = dragObj.m_SkillID;
        msg.m_buttonIndex = drapObj.m_ButtonIndex;
        msg.m_barIndex = drapObj.m_BarIndex;
        Networker.Instance.SendMessage(msg);
    }*/

    public void SendRequestGetDungeonInfo()
    {
        var msg = new U2GS_GetDungeonInfo();
        Networker.Instance.SendMessage(msg);
    }

    public void SendRequestTaskProgressUpdate(UInt32 id)
    {
        var msg = new U2GS_TaskProgressUpdate();
        msg.m_taskID = id;
        msg.m_progress = 1;
        Networker.Instance.SendMessage(msg);
    }

    public void SendRequestMoveTo(UInt64 code, List<Vector2> ptlist)
    {
        var msg = new U2GS_MoveTo();
#if DEBUG_CHECK_SENT_PATH
        ptlist = NetCmdUtils.CheckPath( ref ptlist, false );
#endif
        msg.m_id = code;
        msg.m_posX = ptlist[ptlist.Count - 1].x;
        msg.m_posY = ptlist[ptlist.Count - 1].y;
        var path = new List<PosInfo>();
        for (int i = 0; i < ptlist.Count; ++i)
        {
            PosInfo posInfo = new PosInfo();
            posInfo.m_x = ptlist[i].x;
            posInfo.m_y = ptlist[i].y;
            path.Add(posInfo);
        }
        msg.m_posInfos = path;
        Networker.Instance.SendMessage(msg);

#if _DEBUG
        Character sender = GameSceneManager.Instance.FindEntity(code) as Character;
        SinglePanelManger.Instance.debugsPanel.GetSendMsgInfo(sender, msg);
#endif
    }

    public void SendRequestMoveTo(UInt64 code, Vector2 start, Vector2 target)
    {
        var msg = new U2GS_MoveTo();
        msg.m_id = code;
        msg.m_posX = target.x;
        msg.m_posY = target.y;
        var ptlist = new List<PosInfo>();
        // start point
        var spt = new PosInfo();
        spt.m_x = start.x;
        spt.m_y = start.y;
        ptlist.Add(spt);
        // end point
        var ept = new PosInfo();
        ept.m_x = target.x;
        ept.m_y = target.y;
        ptlist.Add(ept);
        msg.m_posInfos = ptlist;
        Networker.Instance.SendMessage(msg);
#if _DEBUG
        Character sender = GameSceneManager.Instance.FindEntity(code) as Character;
        SinglePanelManger.Instance.debugsPanel.GetSendMsgInfo(sender, msg);
#endif
    }

   /* public void SendRequestAttackHit(GS2U_AttackResultHandled attackRH, UInt32 hitCount, int orientation)
    {
        var msg = new U2GS_AttackHit();
        msg.m_userCode = attackRH.m_userCode;
        msg.m_targetCode = attackRH.m_targetCode;
        msg.m_skillId = attackRH.m_skillId;
        msg.m_serial = attackRH.m_skillId;
        msg.m_hitCount = hitCount;
        msg.m_orienation = (sbyte)orientation;
        msg.m_damgeinfo = new DamageInfo();
        msg.m_attackeResult = new AttackResult();
        Networker.Instance.SendMessage(msg);
#if _DEBUG
        Character sender = GameSceneManager.Instance.FindEntity(msg.m_userCode) as Character;
        SinglePanelManger.Instance.debugsPanel.GetSendMsgInfo(sender, msg);
#endif
    }*/
}
